/*
 * @:
 * @Version: 1.0
 * @Autor: ziwei
 * @Date: 2022-03-15 15:45:20
 * @LastEditors: ziwei
 * @LastEditTime: 2022-03-15 16:03:15
 */
import { createApp } from "vue";
import { createWebHistory,createRouter } from "vue-router";
import App from "./App.vue";
import routes from "../router";

//不能直接挂在，需要切换的时候，调用mount方法时候再去挂载
let history;
let router;
let app;
function render(props={}) {
  history = createWebHistory("/vue");
  router = createRouter({
    history,
    routes,
  });
  app = createApp(App);
  let { container } = props;
  app.use(router).mount(container ? container.querySelector("#app") : document.getElementById("#app"));
}

//乾坤在渲染前 给我提供了一个变量window.__POWERED_BY_QIANKUN__
if(!window.__POWERED_BY_QIANKUN__){//独立运行自己
  render();
}

//需要暴露接入协议
export async function bootstrap() {
  console.log("vue3 app bootstraped");
}

export async function mount(props) {
  console.log("vue3 app mount", props);
  render(props);
}

export async function unmount() {
  console.log("vue3 app unmount");
  history = null;
  router = null;
  app = null;
}
